<?php

require_once($_SERVER['DOCUMENT_ROOT'] . "/public/BaseCms.php");

/**
 * 菜单信息
 * Class Menusinfo
 */
class Menusinfo extends BaseCms
{

    public $tb_name = "menuinfo";
    private $menu_list = array();

    function __construct()
    {
        parent::__construct($this->tb_name);
    }

    /**
     * 根据位置获取菜单信息
     * @param $positionName 位置名称
     * @return array|mixed
     */
    function getDataByPostion($positionName)
    {
        return $this->findList(["show_position" => $positionName]);
    }

    /**
     *
     * @param int $parent_id
     * @param array $menu_list
     * @return array
     */
    function loadMenus($parent_id = 0, &$menu_list = array())
    {
        $datas = $this->findList(["parent_id" => $parent_id]);
        if (!empty($datas)) {
            foreach ($datas as $val) {
                $sub_datas = $this->loadMenus($val["idMenuinfo"]);
                $val["children"] = $sub_datas;
                $menu_list[] = $val;
            }
        }
        return $menu_list;
    }

    /**
     * 根据类别获取数据Id
     * @param $type
     * @return mixed
     */
    function getCategoryIdByType($type)
    {
        $one = $this->findOne(["menu_type" => $type]);
        return $one["idMenuinfo"];
    }

    /**
     * 通过类型获取数据
     * @param $type
     * @return array|mixed
     */
    function loadDataByType($type)
    {
        $cond = ["menu_url" => [$this->param_operation => "like", $this->param_value_key => "%" . $type . ".php"], "is_del" => 0];
        $redata = $this->findList($cond);
        return $redata;
    }

    /**
     * 获取页面类型
     * @return array
     */
    public function pageType()
    {
        $arr = [];
        $arr[] = ["name" => "产品", "type" => "product", "url" => "view/products.php"];
        $arr[] = ["name" => "列表", "type" => "news", "url" => "view/news.php"];
        $arr[] = ["name" => "单页", "type" => "page", "url" => "view/page.php"];
        $arr[] = ["name" => "在线反馈", "type" => "feedback", "url" => "view/feedback.php"];
        $arr[] = ["name" => "友情链接", "type" => "friendlink", "url" => "view/friendlink.php"];
        $arr[] = ["name" => "在线招聘(未实现)", "type" => "job", "url" => "view/job.php"];
        return $arr;
    }
}